/*************************************************************************
	> File Name: stack.cpp
	> Author: Potter
	> Mail: tobewhatwewant@gmail.com 
	> Created Time: 2014年06月01日 星期日 09时48分12秒
 ************************************************************************/

#include<iostream>
using namespace std;

// template <typename T>
template <class T>
class Stack {
    private:
        unsigned int size;
        unsigned int sp;
        T * data;

    public:
        Stack(unsigned int size = 100);
        ~Stack();
        void push(T value);
        T pop();
};

template <class T>
Stack<T>::Stack(unsigned int size) {
    this -> size = size;
    data = new T[size];
    sp = 0;
}

template <class T>
Stack<T>::~Stack() {
    delete [] data;
}

template <class T>
void Stack<T>::push(T value) {
    data[sp++] = value;
}

template <class T>
T Stack<T>::pop() {
    return data[--sp];
}

int main(int argc, char * argv[]) {
    Stack<int> intStack(100);

    intStack.push(1);
    intStack.push(2);
    intStack.push(3);

    cout << intStack.pop() << endl;
    cout << intStack.pop() << endl;
    cout << intStack.pop() << endl;

    return 0;
}
